import { IPSChartSeriesCSCartesian2DEncode } from './ipschart-series-cscartesian2-dencode';
import { IPSChartXAxis } from './ipschart-xaxis';
import { IPSChartYAxis } from './ipschart-yaxis';
import { IPSDEChart } from './ipsdechart';
import { PSDEChartSeriesEncodeImplBase } from './psdechart-series-encode-impl-base';

export class PSDEChartSeriesCSCartesian2DEncodeImpl extends PSDEChartSeriesEncodeImplBase implements IPSChartSeriesCSCartesian2DEncode {
  protected pschartxaxis: IPSChartXAxis | null = null;

  getPSChartXAxis(): IPSChartXAxis | null {
    if (this.pschartxaxis != null) return this.pschartxaxis;
    const value = this.M.getPSChartXAxis;
    if (value == null) {
      return null;
    }
    const ipsdechart = this.getParentPSModelObject('control.chart.IPSDEChart') as IPSDEChart;
    if (ipsdechart != null) {
      this.pschartxaxis = ipsdechart.findPSChartXAxis(value);
    }
    return this.pschartxaxis;
  }

  get psChartXAxis(): IPSChartXAxis | null {
    return this.getPSChartXAxis();
  }

  getPSChartXAxisMust(): IPSChartXAxis {
    const value = this.getPSChartXAxis();
    if (value == null) {
      throw new Error('未指定图表X坐标轴');
    }
    return value;
  }

  protected pschartyaxis: IPSChartYAxis | null = null;

  getPSChartYAxis(): IPSChartYAxis | null {
    if (this.pschartyaxis != null) return this.pschartyaxis;
    const value = this.M.getPSChartYAxis;
    if (value == null) {
      return null;
    }
    const ipsdechart = this.getParentPSModelObject('control.chart.IPSDEChart') as IPSDEChart;
    if (ipsdechart != null) {
      this.pschartyaxis = ipsdechart.findPSChartYAxis(value);
    }
    return this.pschartyaxis;
  }

  get psChartYAxis(): IPSChartYAxis | null {
    return this.getPSChartYAxis();
  }

  getPSChartYAxisMust(): IPSChartYAxis {
    const value = this.getPSChartYAxis();
    if (value == null) {
      throw new Error('未指定图表Y坐标轴');
    }
    return value;
  }

  protected _x: string[] | null = null;

  getX(): string[] | null {
    if (this._x == null) {
      const value = this.M.x;
      if (value == null) {
        return null;
      }
      const arrayNode: any[] = value;
      if (arrayNode.length == 0) {
        return null;
      }
      const list: string[] = [];
      for (let i = 0; i < arrayNode.length; i++) {
        list.push(arrayNode[i]);
      }
      this._x = list;
    }
    return this._x;
  }

  get x(): string[] | null {
    return this.getX();
  }

  protected _y: string[] | null = null;

  getY(): string[] | null {
    if (this._y == null) {
      const value = this.M.y;
      if (value == null) {
        return null;
      }
      const arrayNode: any[] = value;
      if (arrayNode.length == 0) {
        return null;
      }
      const list: string[] = [];
      for (let i = 0; i < arrayNode.length; i++) {
        list.push(arrayNode[i]);
      }
      this._y = list;
    }
    return this._y;
  }

  get y(): string[] | null {
    return this.getY();
  }

  get cls(): string {
    return 'PSDEChartSeriesCSCartesian2DEncodeImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.chart.IPSChartSeriesCSCartesian2DEncode') return true;
    return super.instanceof(cls);
  }
}
